home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLSRC.PAK / FILTVAL.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  2.2 KB  |  112 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1993, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.5  $
  6. //
  7. // Implementation of TFilterValidator, a validator that filters out keys that
  8. // are not in the valid character set.
  9. //----------------------------------------------------------------------------
  10. #pragma hdrignore SECTION
  11. #include <owl/pch.h>
  12. #if !defined(OWL_VALIDATE_H)
  13. # include <owl/validate.h>
  14. #endif
  15. #if !defined(OWL_APPLICAT_H)
  16. # include <owl/applicat.h>
  17. #endif
  18. #if !defined(OWL_APPDICT_H)
  19. # include <owl/appdict.h>
  20. #endif
  21. #if !defined(OWL_FRAMEWIN_H)
  22. # include <owl/framewin.h>
  23. #endif
  24.  
  25. OWL_DIAGINFO;
  26.  
  27. #if !defined(SECTION) || SECTION == 1
  28.  
  29. //
  30. //
  31. //
  32. TFilterValidator::TFilterValidator(const TCharSet& validChars)
  33. :
  34.   TValidator()
  35. {
  36.   ValidChars = validChars;
  37. }
  38.  
  39. //
  40. //
  41. //
  42. bool
  43. TFilterValidator::IsValidInput(char far* str, bool /*suppressFill*/)
  44. {
  45.   for (const char far* p = str; *p; ) {
  46.     uint n = CharSize(p);
  47.     if (n > 1 || !ValidChars.Has((uchar)*p))
  48.       return false;
  49.     p += n;
  50.   }
  51.   return true;
  52. }
  53.  
  54. //
  55. //
  56. //
  57. bool
  58. TFilterValidator::IsValid(const char far* str)
  59. {
  60.   for (const char far* p = str; *p;) {
  61.     uint n = CharSize(p);
  62.     if (n > 1 || !ValidChars.Has((uchar)*p))
  63.       return false;
  64.     p += n;
  65.   }
  66.   return true;
  67. }
  68.  
  69. //
  70. //
  71. //
  72. void
  73. TFilterValidator::Error(TWindow* owner)
  74. {
  75.   PRECONDITION(owner);
  76.   TApplication* app = owner->GetApplication();
  77.   string msg = app->LoadString(IDS_VALINVALIDCHAR);
  78.   owner->MessageBox(msg.c_str(), app->GetName(), MB_ICONEXCLAMATION|MB_OK);
  79. }
  80.  
  81. #endif
  82. #if !defined(SECTION) || SECTION == 2
  83.  
  84. IMPLEMENT_STREAMABLE1(TFilterValidator, TValidator);
  85.  
  86. #if !defined(BI_NO_OBJ_STREAMING)
  87.  
  88. //
  89. //
  90. //
  91. void*
  92. TFilterValidator::Streamer::Read(ipstream& is, uint32 /*version*/) const
  93. {
  94.   ReadBaseObject((TValidator*)GetObject(), is);
  95.   is >> GetObject()->ValidChars;
  96.   return GetObject();
  97. }
  98.  
  99. //
  100. //
  101. //
  102. void
  103. TFilterValidator::Streamer::Write(opstream& os) const
  104. {
  105.   WriteBaseObject((TValidator*)GetObject(), os);
  106.   os << GetObject()->ValidChars;
  107. }
  108.  
  109. #endif  // if !defined(BI_NO_OBJ_STREAMING)
  110.  
  111. #endif
  112.